package com.wrapper;

public class Integer01 {
    public static void main(String[] args) {
        //装箱 int=>Integer
        int n1 = 100;
        System.out.println(getType(n1));
        Integer integer = new Integer(n1);
        Integer integer1 = Integer.valueOf(n1);

        System.out.println(getType(integer));
        System.out.println(getType(integer1));
        // System.out.println();
        //手动拆箱
        //Integer=>int
        int i = integer.intValue();
        System.out.println(getType(i));


        int n2 = 200;
        System.out.println(getType(n2));
        //自动装箱
        Integer integer2 = n2;
        System.out.println(getType(integer2));
        //自动拆箱
        int n3 = integer2;
        System.out.println(getType(n3));


        // TODO Auto-generated method stub
        Integer i1 = new Integer(123);
        Integer i2 = new Integer("123");
        System.out.println("i1=i2:" + (i1 == i2));//false
        System.out.println("i1.equals(i2):" + i1.equals(i2));
        System.out.println(i2);
        System.out.println(i2.toString());//说明重写了toString方法
        Integer i3 = new Integer(128);
        System.out.println(i1.compareTo(i3));//-1
        System.out.println(i1.compareTo(i2));//0
        System.out.println(i3.compareTo(i2));//1
        //(1)Integer-->int    包装对象.intValue()
        //int i=i1.intValue();
        //System.out.println(Integer.max(10, 20));//返回最大值
        //(2)String -->int  包装类类名.parseInt(String s)
        int ii = Integer.parseInt("234");
        //(3)int -->Integer
        Integer i4 = Integer.valueOf(123);
        //(4)int-->String
        String str = ii + "";
        String s = String.valueOf(ii);
        //(5)String-->Integer;
        Integer i5 = new Integer("345");
        //(6)Integer-->String
        String ss = i5.toString();
        System.out.println(ss);

        Double d = 100d;
        //自动装箱 Double.valueOf(100d);
        Float f = 1.5f;
        //自动装箱 Float.valueOf(1.5f);

        //三元运算符是一个整体，会对类型进行提升
        Object obj1 = true ? new Integer(1) : new Double(2.0);
        System.out.println("return obj1 : " + obj1);

        Object obj2;
        if (true) {
            obj2 = new Integer(1);
        } else {
            obj2 = new Double(2.0);
        }
        System.out.println("return obj2 : " + obj2);


    }

    public static String getType(Object o) { //获取变量类型方法
        return o.getClass().toString(); //使用int类型的getClass()方法
    }
}